<?php
namespace Application\pform\a_wan2;


use Application\pform\a_wan\PublicModel;
use Cola\Model;
use Cola\Request;
use Application\pform\a_wan\PlayerModel as BaseAWanPlayer;
class PlayerModel extends BaseAWanPlayer{

    protected $v = 2;


    protected function sign($rows, $sign, $secret=CHAT_KEY)
    {
        return parent::sign($rows, $sign, $secret);
    }


    public function notifyServer()
    {
        $rows = [];
        $rows['channel_id'] = CHANNEL_ID;
        //$rows['channel'] = CHANNEL_ID;
        $rows['xx_game_id'] = $this->get('game_id');
        $rows['server_name'] = $this->get('name');
        $rows['server_id'] = $this->get('sid');
        $rows['event_time'] = strtotime($this->get('open_time'));
        $rows['server_open_type'] = $this->get('type'); // 1:自动开服 2:手动开服

        ksort($rows);
        $res = $this->publicReport('open_server_notice',$rows);

        $this->logfile('notify server:'.json_encode($rows).' result:'.json_encode($res,JSON_UNESCAPED_UNICODE));
        return $this->result(1, '', $res);
    }

    protected function publicReport($report_type,$rows,$is_async=false)
    {
        $url = $is_async ? PUBLIC_ASYNC_URL :PUBLIC_SYNC_URL;
        $salt = SERVER_KEY;
        $rows['timestamp'] = time();
        $rows['report_type'] = $report_type;
        ksort($rows);
        list($before,$rows['sign']) = PublicModel::signV21($rows,$salt);
        $res = $this->curlWay($url,$rows,false);
        $this->logfile('publicReport:'.$report_type.':'.json_encode($rows).' result:'.json_encode($res));
        return $res;
    }

}
